home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / dns / ddt2.0 / cmd / grc < prev    next >
Encoding:
Text File  |  1993-05-27  |  4.4 KB  |  190 lines

  1. #! /usr/local/bin/perl
  2. #
  3. #  grc - glue records checker
  4. #
  5. #  invoke as:
  6. #       grc [-l msglevel]
  7. #
  8. #  Copyright (C) 1992, 1993 PUUG - Grupo Portugues de Utilizadores
  9. #                   do Sistema UNIX
  10. #                1992, 1993 FCCN - Fundacao para o Desenvolvimento dos Meios 
  11. #                                   Nacionais de Calculo Cientifico 
  12. #
  13. #  Authors: Jorge Frazao de Oliveira <frazao@puug.pt>
  14. #           Artur Romao <artur@dns.pt>
  15. #
  16. #  This file is part of the DDT package, Version 2.0.
  17. #
  18. #  Permission to use, copy, modify, and distribute this software and its 
  19. #  documentation for any purpose and without any fee is hereby granted, 
  20. #  provided that the above copyright notice appear in all copies.  Neither 
  21. #  PUUG nor FCCN make any representations about the suitability of this
  22. #  software for any purpose.  It is provided "as is" without express or 
  23. #  implied warranty.
  24.  
  25.  
  26. # =()<push(@INC, "@<LIBDIR>@");>()=
  27. push(@INC, "/usr/local/lib/ddt/cmd");
  28.  
  29. require "ddt.pl";
  30.  
  31.  
  32. # scan the standard input
  33. while (<STDIN>) {
  34.     next if /^;\s+Ignoring info/;    # if commented lines are not 
  35.                     # of this form
  36.     s/^;\s+//;            # check them too
  37.  
  38.     chop;                # strip record separator
  39.     @Field = split(/\s+/, $_);    # break the input line
  40.  
  41.     if (/^\$ORIGIN/) {
  42.         $Origin = $Field[2];    # set to a different origin
  43.     
  44.         next;
  45.     }
  46.  
  47.         if (/^[*\.\-0-9A-Za-z]+/) { 
  48.         $Name = &make_name($Field[1], $Origin);
  49.     }
  50.  
  51.         if (/\tIN\tSOA\t/) {
  52.         &show_zone($Zone);    # show results for the former zone
  53.  
  54.         $Zone = $Name;        # and let's start examinig this new one
  55.  
  56.         # get rid of the past
  57.         undef %Address;
  58.         undef %IsNS;
  59.         undef %IsSubzoneNS;
  60.     }
  61.         elsif (/\tIN\tNS/) {
  62.         &new_NS($Name, $Zone, $Field[$#Field]);    # check the NS record
  63.     }
  64.         elsif (/\tIN\tA/) {
  65.         $Address{$Name, $Field[$#Field]} = 1;    # there's an address 
  66.                             # for this name
  67.     }
  68. }
  69.  
  70. &show_zone($Zone);    # see the last zone
  71.  
  72. exit 0;
  73.  
  74. #
  75. # determine if we're interested in this name server, and why
  76. #
  77. sub new_NS {
  78.     local($name, $zone, $server) = @_;
  79.  
  80.     $server = &tolower($server);
  81.  
  82.         if (&is_below_cut($zone, $name)) {
  83.         $IsSubzoneNS{$server} = 1;    # $server is NS for a sub-zone
  84.                         # of this zone 
  85.         $IsNS{$server}        = 1;    # flag it as a name server
  86.         }
  87.        else {
  88.         if ($name eq $zone) {        # $server is a name server (for
  89.             $IsNS{$server} = 1;    # this zone, that's why we keep
  90.         }                # track of it)
  91.         }
  92. }
  93.  
  94.  
  95. #
  96. # check the necessity and existence of the A RR's for the found name servers
  97. #
  98. sub check_glue_records {
  99.     local($zone) = @_;
  100.     local(*NecessaryGR, *UnnecessaryGR, *MissingGR);
  101.     local($host, $name, $address, @HasAddress);
  102.     local($s, $e, $t);
  103.  
  104.         foreach $host (keys %Address) {
  105.         ($name, $address)  = split($;, $host);
  106.         $HasAddress{$name} = 1;
  107.  
  108.         if ($Level >= 4) {
  109.             $str = sprintf("%s%-25s IN\tA\t%s", 
  110.                        $Lpad[4], $name, $address);
  111.  
  112.             if ($IsNS{$name}) {    # we have a name server...
  113.                 if (&is_below_cut($zone, $name) && 
  114.                    $IsSubzoneNS{$name}) {
  115.                     # ... belonging to a delegated domain,
  116.                     # so we must have its address listed 
  117.                     # in our zone file
  118.  
  119.                     push(@NecessaryGR, $str);
  120.                 }
  121.                 elsif (!&in_THIS_zone($name, $zone)) {
  122.                     # ... whose address can be found
  123.                     # somewhere else in the DNS tree
  124.  
  125.                     push(@UnnecessaryGR, $str);
  126.                 }
  127.             }
  128.         }
  129.     }
  130.  
  131.     if ($Level >= 2) {
  132.         foreach $host (keys %IsNS) {
  133.             if (!$HasAddress{$host} && 
  134.                 &is_below_cut($zone, $host) &&
  135.                         $IsSubzoneNS{$host}) {
  136.                 # this name server belongs to a sub-zone, 
  137.                 # but its address is not listed in this 
  138.                 # zone definition
  139.  
  140.                 push(@MissingGR, sprintf("%-8s%s", "", $host));
  141.             }
  142.         }
  143.     }
  144.  
  145.     if ($#NecessaryGR) {
  146.         $s = $#UnnecessaryGR > 1 ? "s" : "";
  147.  
  148.         print "\n$Lpad[4]Necessary glue record$s (name server$s of delegated domains):";
  149.  
  150.         foreach $str ($[ .. $#NecessaryGR) {
  151.             print shift(@NecessaryGR);
  152.         }
  153.     }
  154.  
  155.         if ($#UnnecessaryGR) {
  156.         $s = $#UnnecessaryGR > 1 ? "s" : "";
  157.  
  158.         print "\n$Lpad[4]Unnecessary glue record$s (if present, should be removed):";
  159.  
  160.         foreach $str ($[ .. $#UnnecessaryGR) {
  161.             print shift(@UnnecessaryGR);
  162.         }
  163.     }
  164.  
  165.         if ($#MissingGR) {
  166.         ($s, $e, $t) = $#MissingGR > 1 ? ("s", "es", "these") :
  167.                              ("", "", "this");
  168.  
  169.         print "\n$Lpad[2]Missing glue record$s (the address$e of $t host$s should be present):";
  170.  
  171.         foreach $str ($[ .. $#MissingGR) {
  172.             print shift(@MissingGR);
  173.         }
  174.     }        
  175. }
  176.  
  177.  
  178. #
  179. # show the results for (real) zones
  180. #
  181. sub show_zone {
  182.     local($zone) = @_;
  183.  
  184.     if ($zone ne "") {
  185.         print "\n ###",  &toupper($zone), "###";
  186.         
  187.         &check_glue_records($zone);
  188.     }
  189. }
  190.